package com.DongBing.controller;

import java.util.Arrays;
import java.util.Map;

import com.DongBing.common.utils.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.DongBing.entity.AttrEntity;
import com.DongBing.service.AttrService;
import com.DongBing.common.utils.PageUtils;
import com.DongBing.common.utils.R;



/**
 * 商品属性
 *
 * @author ¶­±ù
 * @email 861571118@QQ.com
 * @date 2022-05-16 15:56:01
 */
@RestController
@RequestMapping("/product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
		AttrEntity attr = attrService.getById(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody AttrEntity attr){
		attrService.insert(attr);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrEntity attr){
		attrService.updateById(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));
        return R.ok();
    }

    /**
     * 根绝分类的id 获取分类下面的属性
     * @param map map
     * @param catelogId 分类的id
     * @return res
     */
    @GetMapping(value = "/page/{catelogId}")
    public Res<?> AttrList(@RequestBody Map<String,Object> map
            ,@PathVariable("catelogId") String catelogId){
        return attrService.AttrListPage(map,catelogId);
    }

}
